
package com.e885.util.numeric;

import com.e885.log.E885Logger;

/**
 * <br>
 * Copyright: Copyright (c) 2001-2008<br>
 * Company: E885 Group
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 */

public class IntegerUtil
{
	/**
	 * 取得 Integer<br>
	 * 如果有小數點, 那麼將去除小數點<br>
	 * 
	 * @param source
	 * @return
	 */
	public static Integer getInteger( String source )
	{
		if( source == null || source.trim().length() == 0 )
			return null;

		try
		{
			int idx = source.indexOf( "." );

			if( idx == -1 )
				return new Integer( source );
			else
				return new Integer( source.substring( 0, idx ) );
		}
		catch( NumberFormatException e )
		{
			e.printStackTrace();

			E885Logger.utilLog.error( "Can't parse number:" + source );

			return null;
		}
	}

	/**
	 * get the value
	 * 
	 * @param obj
	 * @return
	 */
	public static int getValue( Integer obj )
	{
		if( obj == null )
			return 0;

		return obj.intValue();
	}
}
